package com.ruoyi.driver.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.driver.domain.CarownerVehicleroute;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.driver.service.ICarownerVehiclerouteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆路线Controller
 * 
 * @author Wevon
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/driver/vehicleroute")
public class CarownerVehiclerouteController extends BaseController
{
    @Autowired
    private ICarownerVehiclerouteService carownerVehiclerouteService;

    /**
     * 查询车辆路线列表
     */
    @PreAuthorize("@ss.hasPermi('driver:vehicleroute:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarownerVehicleroute carownerVehicleroute)
    {
        startPage();
        List<CarownerVehicleroute> list = carownerVehiclerouteService.selectCarownerVehiclerouteList(carownerVehicleroute);
        return getDataTable(list);
    }

    /**
     * 导出车辆路线列表
     */
    @PreAuthorize("@ss.hasPermi('driver:vehicleroute:export')")
    @Log(title = "车辆路线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarownerVehicleroute carownerVehicleroute)
    {
        List<CarownerVehicleroute> list = carownerVehiclerouteService.selectCarownerVehiclerouteList(carownerVehicleroute);
        ExcelUtil<CarownerVehicleroute> util = new ExcelUtil<CarownerVehicleroute>(CarownerVehicleroute.class);
        util.exportExcel(response, list, "车辆路线数据");
    }

    /**
     * 获取车辆路线详细信息
     */
    @PreAuthorize("@ss.hasPermi('driver:vehicleroute:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carownerVehiclerouteService.selectCarownerVehiclerouteById(id));
    }

    /**
     * 新增车辆路线
     */
    @PreAuthorize("@ss.hasPermi('driver:vehicleroute:add')")
    @Log(title = "车辆路线", businessType = BusinessType.INSERT)
    @PostMapping
    public int add(@RequestBody CarownerVehicleroute carownerVehicleroute)
    {
       int num = Math.toIntExact(carownerVehiclerouteService.insertCarownerVehicleroute(carownerVehicleroute));
        System.out.println("Ajax的值 = " + num);
        return num;
    }

    /**
     * 修改车辆路线
     */
    @PreAuthorize("@ss.hasPermi('driver:vehicleroute:edit')")
    @Log(title = "车辆路线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarownerVehicleroute carownerVehicleroute)
    {
        return toAjax(carownerVehiclerouteService.updateCarownerVehicleroute(carownerVehicleroute));
    }

    /**
     * 删除车辆路线
     */
    @PreAuthorize("@ss.hasPermi('driver:vehicleroute:remove')")
    @Log(title = "车辆路线", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carownerVehiclerouteService.deleteCarownerVehiclerouteByIds(ids));
    }
}
